#pragma once

#include "VarTableEntry.h"
#include <vector>
#include <map>
using namespace std;

class VarTable{
private:
	int indexCount;
	map<string, VarTableEntry> varIndex;
	map<int, VarTableEntry> revIndex;
public:

	/**
	 * Initialises an empty VarTable
	 */
	VarTable();

	/**
	 * Adds a variable to this VarTanle
	 * @param varName the name of the variable to be added
	 * @param stmtNum the statement number where this variable can be found
	 * @return the index of the variable in the VarTable
	 */
	int addVar(string varName, int stmtNum);

	/**
	 * Adds a node ID to the variable with the given index
	 * @param varIndex the index of the variable
	 * @param nodeID the node ID to be added
	 * @return True if the node ID is successfully added. False if the node ID already exists.
	 */
	bool addVarNodeID(int varIndex, int nodeID);
	
	/**
	 * Retrieves the index of the variable with the given name
	 * @param varName the name of the variable
	 * @return the index of the variable
	 */
	int getIndex(string varName);
	
	/**
	 * Retrieves the name of the variable with the given index
	 * @param varIndex the index of the variable
	 * @return the name of the variable
	 */
	string getVarName(int varIndex);
	
	/** 
	 * Returns the list of statements that contains the variable with the given index
	 * @param varIndex the index of the variable
	 * @return A vector containing the statement numbers where the variable with the given index can be found
	 */
	vector<int> getStmts(int varIndex);
	
	/** 
	 * Returns the list of AST nodes that contains the variable with the given index
	 * @param varIndex the index of the variable
	 * @return A vector containing the AST node IDs where the variable with the given index can be found
	 */
	vector<int> getNodeIDs(int varIndex);

	/**
	 * Returns the size of this VarTable
	 * @return the number of entries contained in this VarTable
	 */
	int size();
};
